package io.bsly.modules.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import io.bsly.common.utils.PageUtils;
import io.bsly.common.utils.R;
import io.bsly.modules.app.entity.localEntity.DyUserLongTermEntity;
import io.bsly.modules.app.entity.localEntity.UserEntity;
import io.bsly.modules.app.pojo.UserFrom;
import io.bsly.modules.app.service.localmaster.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/app/user")
public class DyUserController {
    @Autowired
    UserService userService;


    /**
     * 获取用户列表
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页数" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "limit",value = "每页条数" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userId",value = "用户id" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userName",value = "用户名" , dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "registerDate",value = "注册时间" , dataType = "string", paramType = "query",example = "2021-09-24")
    })
    @GetMapping("/list")
    public R list(UserFrom userFrom){
        PageUtils page =  userService.queryPage(userFrom);
        return R.ok().put("page", page);
    }




    /**
     * 获取用户信息
     */
    @ApiOperation("根据id查询")
    @GetMapping("/info/{id}")
    public R infoById(@PathVariable("id") Integer id){
        UserEntity userEntity = userService.getById(id);
        return R.ok().put("userEntity", userEntity);
    }

    /**
     * 获取用户信息
     */
    @ApiOperation("openId 查询")
    @GetMapping("/info/{openId}")
    public R infoByOpenId(@PathVariable("openId") String openId){
        UserEntity userEntity = userService.getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getOpenid,openId));
        return R.ok().put("userEntity", userEntity);
    }

    /**
     * 修改
     */
    @ApiOperation("根据Id修改用户")
    @PostMapping("/update")
    public R update(@RequestBody UserEntity userEntity){
        userService.updateById(userEntity);
        return R.ok();
    }

}
